home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
xvisrc.zip
/
CMDLINE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-28
|
27KB
|
1,256 lines
/* Copyright (c) 1990,1991,1992 Chris and John Downey */
#ifndef lint
static char *sccsid = "@(#)cmdline.c 2.2 (Chris & John Downey) 8/6/92";
#endif
/***
* program name:
xvi
* function:
PD version of UNIX "vi" editor, with extensions.
* module name:
cmdline.c
* module function:
Command-line handling (i.e. :/? commands) - most
of the actual command functions are in ex_cmds.c.
* history:
STEVIE - ST Editor for VI Enthusiasts, Version 3.10
Originally by Tim Thompson (twitch!tjt)
Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
Heavily modified by Chris & John Downey
***/
#include "xvi.h"
#ifdef MEGAMAX
overlay "cmdline"
#endif
/*
* The next two variables contain the bounds of any range
* given in a command. If no range was given, both will be NULL.
* If only a single line was given, u_line will be NULL.
* The a_line variable is used for those commands which take
* a third line specifier after the command, e.g. "move", "copy".
*/
static Line *l_line, *u_line;
static Line *a_line;
/*
* Definitions for all ex commands.
*/
#define EX_ENOTFOUND -1 /* command not found */
#define EX_EAMBIGUOUS -2 /* could be more than one */
#define EX_ECANTFORCE -3 /* ! given where not appropriate */
#define EX_EBADARGS -4 /* inappropriate args given */
#define EX_NOCMD 1
#define EX_SHCMD 2
#define EX_UNUSED 3 /* unused */
#define EX_AMPERSAND 4
#define EX_EXBUFFER 5
#define EX_LSHIFT 6
#define EX_EQUALS 7
#define EX_RSHIFT 8
#define EX_COMMENT 9
#define EX_ABBREVIATE 10
#define EX_APPEND 11
#define EX_ARGS 12
#define EX_BUFFER 13
#define EX_CHDIR 14
#define EX_CHANGE 15
#define EX_CLOSE 16
#define EX_COMPARE 17
#define EX_COPY 18
#define EX_DELETE 19
#define EX_ECHO 20
#define EX_EDIT 21
#define EX_EX 22
#define EX_FILE 23
#define EX_GLOBAL 24
#define EX_HELP 25
#define EX_INSERT 26
#define EX_JOIN 27
#define EX_K 28
#define EX_LIST 29
#define EX_MAP 30
#define EX_MARK 31
#define EX_MOVE 32
#define EX_NEXT 33
#define EX_NUMBER 34
#define EX_OPEN 35
#define EX_PRESERVE 36
#define EX_PRINT 37
#define EX_PUT 38
#define EX_QUIT 39
#define EX_READ 40
#define EX_RECOVER 41
#define EX_REWIND 42
#define EX_SET 43
#define EX_SHELL 44
#define EX_SOURCE 45
#define EX_SPLIT 46
#define EX_SUSPEND 47
#define EX_SUBSTITUTE 48
#define EX_TAG 49
#define EX_UNABBREV 50
#define EX_UNDO 51
#define EX_UNMAP 52
#define EX_V 53
#define EX_VERSION 54
#define EX_VISUAL 55
#define EX_WN 56
#define EX_WQ 57
#define EX_WRITE 58
#define EX_XIT 59
#define EX_YANK 60
#define EX_Z 61
#define EX_GOTO 62
#define EX_TILDE 63
/*
* Table of all ex commands, and whether they take an '!'.
*
* Note that this table is in strict order, sorted on
* the ASCII value of the first character of the command.
*
* The priority field is necessary to resolve clashes in
* the first one or two characters; so each group of commands
* beginning with the same letter should have at least one
* priority 1, so that there is a sensible default.
*
* Commands with argument type ec_rest need no delimiters;
* they need only be matched. This is really only used for
* single-character commands like !, " and &.
*/
static struct ecmd {
char *ec_name;
short ec_command;
short ec_priority;
unsigned ec_flags;
/*
* Flags: EXCLAM means can use !, FILEXP means do filename
* expansion, INTEXP means do % and # expansion. EXPALL means
* do INTEXP and FILEXP (they are done in that order).
*
* EC_RANGE0 means that the range specifier (if any)
* may include line 0.
*/
# define EC_EXCLAM 0x1
# define EC_FILEXP 0x2
# define EC_INTEXP 0x4
# define EC_EXPALL EC_FILEXP|EC_INTEXP
# define EC_RANGE0 0x8
enum {
ec_none, /* no arguments after command */
ec_strings, /* whitespace-separated strings */
ec_1string, /* like ec_strings but only one */
ec_line, /* line number or target argument */
ec_rest, /* rest of line passed entirely */
ec_nonalnum, /* non-alphanumeric delimiter */
ec_1lower /* single lower-case letter */
} ec_arg_type;
} cmdtable[] = {
/* name command priority exclam */
/*
* The zero-length string is used for the :linenumber command.
*/
"", EX_NOCMD, 1, EC_RANGE0, ec_none,
"!", EX_SHCMD, 0, EC_INTEXP, ec_rest,
"#", EX_NUMBER, 0, 0, ec_none,
"&", EX_AMPERSAND, 0, 0, ec_rest,
"*", EX_EXBUFFER, 0, 0, ec_rest,
"<", EX_LSHIFT, 0, 0, ec_none,
"=", EX_EQUALS, 0, 0, ec_none,
">", EX_RSHIFT, 0, 0, ec_none,
"@", EX_EXBUFFER, 0, 0, ec_rest,
"\"", EX_COMMENT, 0, 0, ec_rest,
"abbreviate", EX_ABBREVIATE, 0, 0, ec_strings,
"append", EX_APPEND, 1, 0, ec_none,
"args", EX_ARGS, 0, 0, ec_none,
"buffer", EX_BUFFER, 0, EC_EXPALL, ec_1string,
"cd", EX_CHDIR, 1, EC_EXPALL, ec_1string,
"change", EX_CHANGE, 2, 0, ec_none,
"chdir", EX_CHDIR, 1, EC_EXPALL, ec_1string,
"close", EX_CLOSE, 1, EC_EXCLAM, ec_none,
"compare", EX_COMPARE, 0, 0, ec_none,
"copy", EX_COPY, 1, 0, ec_line,
"delete", EX_DELETE, 0, 0, ec_none,
"echo", EX_ECHO, 0, EC_INTEXP, ec_strings,
"edit", EX_EDIT, 1, EC_EXCLAM|EC_EXPALL, ec_1string,
"ex", EX_EX, 0, EC_EXPALL, ec_1string,
"file", EX_FILE, 0, EC_EXPALL, ec_1string,
"global", EX_GLOBAL, 0, EC_EXCLAM, ec_nonalnum,
"help", EX_HELP, 0, 0, ec_none,
"insert", EX_INSERT, 0, 0, ec_none,
"join", EX_JOIN, 0, 0, ec_none,
"k", EX_K, 0, 0, ec_1lower,
"list", EX_LIST, 0, 0, ec_none,
"map", EX_MAP, 0, EC_EXCLAM, ec_strings,
"mark", EX_MARK, 0, 0, ec_1lower,
"move", EX_MOVE, 1, 0, ec_line,
"next", EX_NEXT, 1, EC_EXCLAM|EC_EXPALL, ec_strings,
"number", EX_NUMBER, 0, 0, ec_none,
"open", EX_OPEN, 0, 0, ec_none,
"preserve", EX_PRESERVE, 0, 0, ec_none,
"print", EX_PRINT, 1, 0, ec_none,
"put", EX_PUT, 0, EC_RANGE0, ec_none,
"quit", EX_QUIT, 0, EC_EXCLAM, ec_none,
"read", EX_READ, 1, EC_EXPALL|EC_RANGE0, ec_1string,
"recover", EX_RECOVER, 0, 0, ec_none,
"rewind", EX_REWIND, 0, EC_EXCLAM, ec_none,
"set", EX_SET, 0, 0, ec_strings,
"shell", EX_SHELL, 0, 0, ec_none,
"source", EX_SOURCE, 0, EC_EXPALL, ec_1string,
"split", EX_SPLIT, 0, 0, ec_none,
"stop", EX_SUSPEND, 0, 0, ec_none,
"substitute", EX_SUBSTITUTE, 1, 0, ec_nonalnum,
"suspend", EX_SUSPEND, 0, 0, ec_none,
"t", EX_COPY, 1, 0, ec_line,
"tag", EX_TAG, 0, EC_EXCLAM, ec_1string,
"unabbreviate", EX_UNABBREV, 0, 0, ec_strings,
"undo", EX_UNDO, 1, 0, ec_none,
"unmap", EX_UNMAP, 0, EC_EXCLAM, ec_strings,
"v", EX_V, 1, 0, ec_nonalnum,
"version", EX_VERSION, 0, 0, ec_none,
"visual", EX_VISUAL, 0, EC_EXCLAM|EC_EXPALL, ec_1string,
"wn", EX_WN, 0, EC_EXCLAM, ec_none,
"wq", EX_WQ, 0, EC_EXCLAM|EC_EXPALL, ec_1string,
"write", EX_WRITE, 1, EC_EXCLAM|EC_EXPALL, ec_1string,
"xit", EX_XIT, 0, 0, ec_none,
"yank", EX_YANK, 0, 0, ec_none,
"z", EX_Z, 0, 0, ec_none,
"|", EX_GOTO, 0, 0, ec_none,
"~", EX_TILDE, 0, 0, ec_rest,
NULL, 0, 0, 0, ec_none,
};
/*
* Internal routine declarations.
*/
static int decode_command P((char **, bool_t *, struct ecmd **));
static bool_t get_line P((char **, Line **));
static bool_t get_range P((char **));
static void badcmd P((bool_t, char *));
static char *show_line P((void));
static char *expand_percents P((char *));
/*
* These are used for display mode.
*/
static Line *curline;
static Line *lastline;
static bool_t do_line_numbers;
/*
* Macro to skip over whi